package com.wego.controller.admin;

import com.wego.bean.PageBean;
import com.wego.bean.ResultBean;
import com.wego.converter.GameDataConverter;
import com.wego.domain.details.GameDataDetails;
import com.wego.domain.dto.GameDataDTO;
import com.wego.domain.entity.GameData;
import com.wego.domain.query.GameDataQuery;
import com.wego.domain.vo.GameDataVO;
import com.wego.service.GameDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游戏数据(tb_gameData)表控制层
 *
 */
@RestController
@RequestMapping("/admin/gameData")
public class AdminGameDataController {
    @Autowired
    private GameDataService gameDataService;
    @Autowired
    private GameDataConverter gameDataConverter;

    @GetMapping("/page")
    public ResultBean<PageBean<GameDataVO>> page(GameDataQuery gameDataQuery) {
        final PageBean<GameData> gameDataPageBean = gameDataService.getPage(gameDataQuery);
        final PageBean<GameDataVO> pageBean = gameDataConverter.entityPageBean2voPageBean(gameDataPageBean);
        return ResultBean.success(pageBean);
    }

    @GetMapping("/{id}")
    public ResultBean<GameDataDetails> getDetails(@PathVariable("id") Integer id) {
        final GameData gameData = gameDataService.getById(id);
        final GameDataDetails gameDataDetails = gameDataConverter.gameData2gameDataDetails(gameData);
        return ResultBean.success(gameDataDetails);
    }

    @PutMapping
    public ResultBean<Void> update(@RequestBody GameDataDTO gameDataDTO) {
        final GameData gameData = gameDataConverter.dto2entity(gameDataDTO);
        gameDataService.update(gameData);
        return ResultBean.success("修改成功!", null);
    }

    @PostMapping
    public ResultBean<Void> insert(@RequestBody GameDataDTO gameDataDTO) {
        final GameData gameData = gameDataConverter.dto2entity(gameDataDTO);
        gameDataService.insert(gameData);
        return ResultBean.success("添加成功!", null);
    }

    @DeleteMapping
    public ResultBean<Void> batchDelete(@RequestParam List<Integer> ids) {
        gameDataService.deleteByIds(ids);
        return ResultBean.success("批量删除成功!", null);
    }

}
